package edu.xhu.utils.common;

import lombok.extern.slf4j.Slf4j;

import java.security.SecureRandom;
import java.util.Base64;

@Slf4j
public class SaltGenerator {

    private static final int length = 16;

    public static String generateSalt() {
        SecureRandom random = new SecureRandom();
        try {
            SecureRandom sha1PRNG = SecureRandom.getInstance("SHA1PRNG");
            sha1PRNG.setSeed(System.currentTimeMillis());
        } catch (Exception e) {
            log.error("error meg:", e);
        }
        byte[] saltBytes = new byte[length];
        random.nextBytes(saltBytes);
        return Base64.getEncoder().encodeToString(saltBytes);
    }

    public static void main(String[] args) {
        System.out.println(generateSalt());
    }
}
